package com.edu.exam.enums;

/**
 * 资源类型枚举
 * 
 * @author S-01 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
public enum ResourceType {
    VENUE("venue", "考场"),
    INVIGILATOR("invigilator", "监考员"),
    EQUIPMENT("equipment", "设备"),
    MATERIAL("material", "材料"),
    SOFTWARE("software", "软件"),
    SERVICE("service", "服务");

    private final String code;
    private final String description;

    ResourceType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码查找枚举值
     *
     * @param code 枚举代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码不存在
     */
    public static ResourceType fromCode(String code) {
        for (ResourceType type : ResourceType.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown resource type code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 枚举描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static ResourceType fromDescription(String description) {
        for (ResourceType type : ResourceType.values()) {
            if (type.description.equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown resource type description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}
